<?php
   class Order extends MY_Controller{
	   public function __construct(){
		   parent::__construct();
		   $this->load->model("model_order");
           $this->load->helper('mail_helper');
	   }
	   public function index(){
		   $id = (int)$this->uri->segment(4);
		   $type = $this->uri->segment(5);
		   $data['result'] 	= $this->model_order->getdata($id,$type);
		   if($data['result'] == NULL){
			   redirect(base_url());
		   }
		   //$this->debug($data['result']);
		   $data['title']     = "Booking";
		   $data['config']    = $this->config();
		   $data['extends']   = $type;
		   $this->load->view("order/layout",$data);
	   }
       public function thank(){
           $data['ship_budget'] 	= $this->type_ship(1);
           $data['ship_superior'] 	= $this->type_ship(2);
           $data['ship_deluxe'] 	= $this->type_ship(3);
           $data['ship_luxury'] 	= $this->type_ship(4);
           $data['ship_premium'] 	= $this->type_ship(5);
           $data['ship_charter'] 	= $this->type_ship(6);
           $data['title']     = "Thanks!";
           $data['config']    = $this->config();
           $data['listships'] = $this->listships();
           $this->load->view("order/thank/layout",$data);
       }
	   public function process(){
		   $name  	= $this->fillter($this->input->post("name"));
		   $email 	= $this->fillter($this->input->post("email"));
		   $phone 	= $this->fillter($this->input->post("phone"));
		   $add 	= $this->fillter($this->input->post("address"));
		   $country	= $this->fillter($this->input->post("country"));
		   $title	= $this->input->post("title");
		   $length	= $this->input->post("length");		   
		   $adults  = $this->fillter($this->input->post("adults"));
		   $children= $this->fillter($this->input->post("children"));
		   $child   = $this->fillter($this->input->post("child"));
		   $start	= $this->fillter($this->input->post("start"));
		   $finds   = $this->fillter($this->input->post("find"));
		   $info  	=  $this->fillter($this->input->post("info"));
		   $db = array(
		   		"order_name" 	=> $name,
				"order_email"	=> $email,
				"order_phone"	=> $phone,
				"order_add"		=> $add,
				"order_country"	=> $country,
				"order_title"	=> $title,
				"order_length"	=> $length,
				"order_adults" 	=> $adults,
				"order_child51"	=> $children,
				"order_child05"	=> $child,
				"order_start"	=> $start,
				"order_find"	=> $finds,
				"order_info"	=> $info,
				"order_status"	=> "1",
				"order_date"	=> date("d/m/Y H:i:s")
		   );
			$null = "/^[a-zA-Z]{1}[a-zA-Z0-9._]{3,25}\@[a-zA-Z0-9]{3,}\.[a-zA-Z.]{2,8}$/";
			if(preg_match($null,$email)){
				$this->model_order->insert($db);
				//$this->sendmail($name, $email, $phone, $add, $country, $tour, $adults,
					//$children, $child, $start, $single, $double, $twin, $triple, $finds, $info,$type);
				echo "<p style='color:green;font-weight:bold'>Your booking has been sent, we will contact you shortly.Thank you</p>";
			}else{
				echo "false";
			}
	   }
       function sendmail($name, $email, $phone, $add, $country, $tour, $adults,$children, $child, $start, $single, $double, $twin, $triple, $finds, $info,$type)
       {
           //go noi dung theo mau thu A3
           $mesnger = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                    <html>
                    <head>
                    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                    </head>
                    <body>
                    <h2 style="font-size: 16px;">BOOKING BEST HALONG CRUISES</h2>
                    <br/><br/>
                    <p>CONTACT INFORMATION </p>

            ';
           $mesnger .= "<p><strong> Full name  : </strong>  $name </p> ";
           $mesnger .= "<p><strong> Email : </strong>  $email </p> ";
           $mesnger .= "<p><strong>Country :  </strong> $country </p>";
           $mesnger .= "<p><strong>Address : </strong>  $add </p> ";
           $mesnger .= "<p><strong>Phone No :  </strong>  $phone </p> ";
           $mesnger .= "<p><strong>Name of cruise : </strong> $tour  Duration of Cruise</p> ";
           $mesnger .= "<p><strong>Number of Adults : </strong>  $adults </p>";
           $mesnger .= "<p><strong>Number of Children under 5 years old :  </strong> $child </p> ";
           $mesnger .= "<p><strong>Number of Children from 5-12 years old : </strong> $start</p>";
           $mesnger .= "<p><strong>Single room : </strong> $single </p> ";
           $mesnger .= "<p><strong>Double room  : </strong> $double </p> ";
           $mesnger .= "<p><strong>Twin room : </strong> $twin </p> ";
           $mesnger .= "<p><strong>Triple room : </strong> $triple </p> ";
           $mesnger .= "<p><strong>Type of room  : </strong> $type </p> ";
           $mesnger .= "<p><strong>How did you find us : </strong> $finds </p> ";
           $mesnger .= "<p><strong>Other requests  : </strong> $info </p> ";
           $mesnger .= 'IP address: '. $_SERVER['REMOTE_ADDR'] .'';
           $mesnger .= "<br/><br/><br/>";
           $mesnger .= "<p>http://bestcruiseshalong.com/</p>";

           $mesnger .= '</body>
            </html> ';
           send_mail_helper('info@bestcruiseshalong.com', 'BOOKING CRUISES FORM', $mesnger);
       }
   }
